package com.app.service.impl;

import com.app.entity.Course;
import com.app.entity.bo.CourseQueryBo;
import com.app.mapper.CourseMapper;
import com.app.service.CourseCollectionService;
import com.app.service.CourseService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yeyuan
 * @since 2021-12-26
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {


    @Override
    public List<Course> selectByNameTeacher(String condition) {
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper<>();
        //姓名或课程名
        wrapper.eq(StringUtils.isNotEmpty(condition),Course::getCourseName,condition)
                .or().eq(StringUtils.isNotEmpty(condition),Course::getCourseName,condition);

        return getBaseMapper().selectList(wrapper);
    }

    @Override
    public List<Course> selectByQueryBo(CourseQueryBo courseQueryBo) {
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(courseQueryBo.getCategory()),Course::getCategory,courseQueryBo.getCategory());
        wrapper.eq(StringUtils.isNotEmpty(courseQueryBo.getStatus()),Course::getStatus,courseQueryBo.getStatus());
        wrapper.eq(StringUtils.isNotEmpty(courseQueryBo.getCollege()),Course::getCollege,courseQueryBo.getCollege());
        wrapper.like(StringUtils.isNotEmpty(courseQueryBo.getTeacherName()),Course::getTeacherName,courseQueryBo.getTeacherName()).or()
                .like(StringUtils.isNotEmpty(courseQueryBo.getCourseName()),Course::getCourseName,courseQueryBo.getCourseName());




        return getBaseMapper().selectList(wrapper);
    }



    @Override
    public int addCourse(Course course) {
        return getBaseMapper().insert(course);
    }



}
